﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AppGPS.Helper;
using Models;

namespace AppGPS.ViewModels
{
    public class UserRequest 
    {
        string _host = App.dataShare.szHost;
        APIRequest<UserResult> _apiUser = new APIRequest<UserResult>();
        public UserRequest(string Host)
        {
            _host = Host;
        }
        public async Task<bool> UsernameExists(string Username)
        {
            var Result = await _apiUser.GetRequestAsync(_host, "api/user/GetUserByName?Username=" + Username);

            if (Result == null) return false;
            else
                return true;
        }
        public async Task<UserResult> CheckLogin(string Username, string Password)
        {
            string Parameter = string.Format("api/Login/GetCheckLogin?Username={0}&Password={1}", Username, Password);

            var Result = await _apiUser.GetRequestAsync(_host, Parameter);

            return Result;
        }
        public async Task<UserResult> CreateAccount(UserResult data)
        {
            var Result = await _apiUser.PostRequestAsync(_host, "api/user/CreateUser",data);

            return Result;
        }
        public async Task<bool> ChangerPassword(UserResult data)
        {
            var Result = await _apiUser.PutRequestAsync(_host, "api/user/PutUpdate", data);

            return Result;
        }

    }
}
